<?php
/* SVN FILE: $Id: reorder.php 233 2009-09-29 01:30:25Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Plugin Ordering
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 233 $
* @lastrevision $Date: 2009-09-29 01:30:25 +0000 (Tue, 29 Sep 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-09-29 01:30:25 +0000 (Tue, 29 Sep 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/modules_admin/plugin/reorder.php $
*/


if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class admin_ibmarket_plugin_reorder extends ipsCommand
{
	/**
	 * Skin object
	 *
	 * @access	private
	 * @var		object			Skin templates
	 */
	private $html;
	
	/**
	 * Main class entry point
	 *
	 * @access	public
	 * @param	object		ipsRegistry reference
	 * @return	void		[Outputs to screen]
	 */
	public function doExecute( ipsRegistry $registry )
	{
		$this->registry->getClass('class_permissions')->checkPermissionAutoMsg( 'manage_plugin' );
		
		$this->html = $this->registry->output->loadTemplate('cp_skin_plugins');
		
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'admin_market', 'admin_plugins' ) );
		
		foreach($this->caches['market_plugin'] as $plugin)
		{
			if(!isset($this->request['order'][$plugin['directory']]))
			{
				continue;
			}
			$this->request['order'][$plugin['directory']] = intval($this->request['order'][$plugin['directory']]);
			if(!$this->request['order'][$plugin['directory']])
			{
				continue;
			}
			$order = array('position' => $this->request['order'][$plugin['directory']]);
			$this->DB->update('market_plugins',$order,"directory='".$plugin['directory']."'");
		}
		
		ipsRegistry::cache()->rebuildCache('market_plugin','ibmarket');
		
		$this->registry->output->redirect( $this->settings['base_url']."module=plugin&amp;section=setup", $this->lang->words['plugins_reordered'] );
	}
}